<template>
  <div class="hello">
    <!-- <h1>{{ msg }}</h1>
    <p>
      For a guide and recipes on how to configure / customize this project,<br>
      check out the
      <a href="https://cli.vuejs.org" target="_blank" rel="noopener">vue-cli documentation</a>.
    </p>
    <h3>Installed CLI Plugins</h3>
    <ul>
      <li><a href="https://github.com/vuejs/vue-cli/tree/dev/packages/%40vue/cli-plugin-babel" target="_blank" rel="noopener">babel</a></li>
      <li><a href="https://github.com/vuejs/vue-cli/tree/dev/packages/%40vue/cli-plugin-eslint" target="_blank" rel="noopener">eslint</a></li>
    </ul>
    <h3>Essential Links</h3>
    <ul>
      <li><a href="https://vuejs.org" target="_blank" rel="noopener">Core Docs</a></li>
      <li><a href="https://forum.vuejs.org" target="_blank" rel="noopener">Forum</a></li>
      <li><a href="https://chat.vuejs.org" target="_blank" rel="noopener">Community Chat</a></li>
      <li><a href="https://twitter.com/vuejs" target="_blank" rel="noopener">Twitter</a></li>
      <li><a href="https://news.vuejs.org" target="_blank" rel="noopener">News</a></li>
    </ul>
    <h3>Ecosystem</h3>
    <ul>
      <li><a href="https://router.vuejs.org" target="_blank" rel="noopener">vue-router</a></li>
      <li><a href="https://vuex.vuejs.org" target="_blank" rel="noopener">vuex</a></li>
      <li><a href="https://github.com/vuejs/vue-devtools#vue-devtools" target="_blank" rel="noopener">vue-devtools</a></li>
      <li><a href="https://vue-loader.vuejs.org" target="_blank" rel="noopener">vue-loader</a></li>
      <li><a href="https://github.com/vuejs/awesome-vue" target="_blank" rel="noopener">awesome-vue</a></li>
    </ul> -->

    <el-form  >
      <base-form :model.sync="model" 
      :ref="ref" 
      :form-items="formItems2" 
      label-width="auto"
      label-position="top"
      :collapse = "false"
      :is-form="false"
      >

      <template v-slot:testSlot="prop">
        <div>{{ `我是-${prop.item.label}` }}</div>
      </template>
      <template v-slot:append-append="prop">
        <div style="width: 20px;height: 40px; background-color: red;"></div>
      </template>
      <el-form-item style="width: 100%; text-align: center; margin-top: 20px;">
        <el-button type="primary" @click="submitForm('ruleForm')">立即创建</el-button>
        <el-button @click="resetForm('ruleForm')">重置</el-button>
      </el-form-item>
    </base-form>
    </el-form>
    
  </div>
</template>

<script>
export default {
  name: 'HelloWorld',
  components: { BaseForm: resolve => require(['../components/BaseForm/BaseForm'], resolve) },
  props: {
    msg: String
  },
  data() {
    const options  =  [{
          value: 'zhinan',
          label: '指南',
          children: [{
            value: 'shejiyuanze',
            label: '设计原则',
            children: [{
              value: 'yizhi',
              label: '一致'
            }, {
              value: 'fankui',
              label: '反馈'
            }, {
              value: 'xiaolv',
              label: '效率'
            }, {
              value: 'kekong',
              label: '可控'
            }]
          }, {
            value: 'daohang',
            label: '导航',
            children: [{
              value: 'cexiangdaohang',
              label: '侧向导航'
            }, {
              value: 'dingbudaohang',
              label: '顶部导航'
            }]
          }]
        }, {
          value: 'zujian',
          label: '组件',
          children: [{
            value: 'basic',
            label: 'Basic',
            children: [{
              value: 'layout',
              label: 'Layout 布局'
            }, {
              value: 'color',
              label: 'Color 色彩'
            }, {
              value: 'typography',
              label: 'Typography 字体'
            }, {
              value: 'icon',
              label: 'Icon 图标'
            }, {
              value: 'button',
              label: 'Button 按钮'
            }]
          }, {
            value: 'form',
            label: 'Form',
            children: [{
              value: 'radio',
              label: 'Radio 单选框'
            }, {
              value: 'checkbox',
              label: 'Checkbox 多选框'
            }, {
              value: 'input',
              label: 'Input 输入框'
            }, {
              value: 'input-number',
              label: 'InputNumber 计数器'
            }, {
              value: 'select',
              label: 'Select 选择器'
            }, {
              value: 'cascader',
              label: 'Cascader 级联选择器'
            }, {
              value: 'switch',
              label: 'Switch 开关'
            }, {
              value: 'slider',
              label: 'Slider 滑块'
            }, {
              value: 'time-picker',
              label: 'TimePicker 时间选择器'
            }, {
              value: 'date-picker',
              label: 'DatePicker 日期选择器'
            }, {
              value: 'datetime-picker',
              label: 'DateTimePicker 日期时间选择器'
            }, {
              value: 'upload',
              label: 'Upload 上传'
            }, {
              value: 'rate',
              label: 'Rate 评分'
            }, {
              value: 'form',
              label: 'Form 表单'
            }]
          }, {
            value: 'data',
            label: 'Data',
            children: [{
              value: 'table',
              label: 'Table 表格'
            }, {
              value: 'tag',
              label: 'Tag 标签'
            }, {
              value: 'progress',
              label: 'Progress 进度条'
            }, {
              value: 'tree',
              label: 'Tree 树形控件'
            }, {
              value: 'pagination',
              label: 'Pagination 分页'
            }, {
              value: 'badge',
              label: 'Badge 标记'
            }]
          }, {
            value: 'notice',
            label: 'Notice',
            children: [{
              value: 'alert',
              label: 'Alert 警告'
            }, {
              value: 'loading',
              label: 'Loading 加载'
            }, {
              value: 'message',
              label: 'Message 消息提示'
            }, {
              value: 'message-box',
              label: 'MessageBox 弹框'
            }, {
              value: 'notification',
              label: 'Notification 通知'
            }]
          }, {
            value: 'navigation',
            label: 'Navigation',
            children: [{
              value: 'menu',
              label: 'NavMenu 导航菜单'
            }, {
              value: 'tabs',
              label: 'Tabs 标签页'
            }, {
              value: 'breadcrumb',
              label: 'Breadcrumb 面包屑'
            }, {
              value: 'dropdown',
              label: 'Dropdown 下拉菜单'
            }, {
              value: 'steps',
              label: 'Steps 步骤条'
            }]
          }, {
            value: 'others',
            label: 'Others',
            children: [{
              value: 'dialog',
              label: 'Dialog 对话框'
            }, {
              value: 'tooltip',
              label: 'Tooltip 文字提示'
            }, {
              value: 'popover',
              label: 'Popover 弹出框'
            }, {
              value: 'card',
              label: 'Card 卡片'
            }, {
              value: 'carousel',
              label: 'Carousel 走马灯'
            }, {
              value: 'collapse',
              label: 'Collapse 折叠面板'
            }]
          }]
        }, {
          value: 'ziyuan',
          label: '资源',
          children: [{
            value: 'axure',
            label: 'Axure Components'
          }, {
            value: 'sketch',
            label: 'Sketch Templates'
          }, {
            value: 'jiaohu',
            label: '组件交互文档'
          }]
        }]
    return {
      options: options,
      model: {
        text: '',
        textarea: '',
        integer: '',
        decimal: '',
        select: '',
        cascader:[],
        info: '只展示, 不可编辑'
      },
      ref: 'form',
      formItems: [
        {
          type: 'group',
          label: '基本信息',
          children: [
            { label: '单行文本', prop: 'text', type: 'text', component: 'el-input', },
            {
              label: '前置',
              prop: 'prepend',
              type: 'text',
              component: 'el-input',
              slots: { prepend: 'http://' },
              required: true
            },
            {
              label: '后置',
              prop: 'append',
              type: 'text',
              component: 'el-input',

              slots: { append: '.com' }, span: 24
            },
            // { label: '文本域', prop: 'textarea',autosize: { minRows: 2, maxRows: 6 }, type: 'textarea', component: 'el-input', span: 12 },
          ]
        },
        {
          type: 'group',
          label: '个人信息',
          children: [
          { label: '整数', prop: 'integer', type: 'integer', component: 'number-input' },
            { label: '小数', prop: 'decimal', type: 'decimal', component: 'number-input' },
            { label: '时间', prop: 'date', type: 'date', component: 'el-date-picker', required: false },
            {
              label: '选择器',
              prop: 'select',
              type: 'select',
              component: 'el-select',
              select: [
                { label: '选项一', value: 'select1' },
                { label: '选项二', value: 'select2' },
                { label: '选项三', value: 'select3' },
                { label: '选项四', value: 'select4' }
              ],
              clearable: true
            },
            {
              label: '中文',
              prop: 'chinese',
              type: 'text',
              reg: /^[\u4E00-\u9FA5]*$/,
              component: 'reg-input'
            },
            {
              label: '数字',
              prop: 'number',
              type: 'text',
              reg: /^-?(\d*|\d+(\.\d*)?)$/,
              component: 'reg-input'
            },
            {
              label: 'Email',
              prop: 'email',
              type: 'text',
              reg: /^([A-Za-z0-9_\-.])+@([A-Za-z0-9_\-.])+\.([A-Za-z]{2,4})$/,
              component: 'reg-input'
            },
            {
              label: '手机号',
              prop: 'phone',
              type: 'text',
              reg: /^1([3456789]\d{0,9})?$/,
              len: 11,
              component: 'reg-input'
            },
            {
              label: '身份证号',
              prop: 'idCard',
              type: 'text',
              reg: /^[1-9]\d{5}(18|19|([23]\d))\d{2}((0[1-9])|(10|11|12))(([0-2][1-9])|10|20|30|31)\d{3}[0-9Xx]$/,
              component: 'reg-input'
            },
            {
              label: '级联选择器',
              prop: 'cascader',
              type: 'cascader',
              component: 'el-cascader',
              options: options,
              style: { width: '100%' }
            },
            { label: '不可编辑', prop: 'info', type: 'info', component: 'span' }
          ]
        }
      ],
      formItems2: [
      { label: '单行文本', prop: 'text', type: 'text', component: 'el-input', },
            {
              label: '前置',
              prop: 'prepend',
              type: 'text',
              component: 'el-input',
              slots: { prepend: 'http://' },
              required: true
            },
            {
              label: '插槽',
              prop: 'testSlot',
              type: 'text',
              isSlot: true,
              required: true,
            },
            {
              label: '后置',
              prop: 'append',
              type: 'text',
              component: 'el-input',

              slots: { append: '.com' }
              , span: 24
            },
            // { label: '文本域', prop: 'textarea',autosize: { minRows: 2, maxRows: 6 }, type: 'textarea', component: 'el-input', span: 12 },
            { label: '整数', prop: 'integer', type: 'integer', component: 'number-input' },
            { label: '小数', prop: 'decimal', type: 'decimal', component: 'number-input' },
            { label: '时间', prop: 'date', type: 'date', component: 'el-date-picker', required: false },
            {
              label: '选择器',
              prop: 'select',
              type: 'select',
              component: 'el-select',
              selectProps: {
                label: 'label',
                value: 'customValue'
              },
              select: [
                { label: '选项一', customValue: 'select1' },
                { label: '选项二', customValue: 'select2' },
                { label: '选项三', customValue: 'select3' },
                { label: '选项四', customValue: 'select4' }
              ],
              events: {
                change: this.submitForm
              }
            },
            {
              label: '中文',
              prop: 'chinese',
              type: 'text',
              reg: /^[\u4E00-\u9FA5]*$/,
              component: 'reg-input'
            },
            {
              label: '数字',
              prop: 'number',
              type: 'text',
              reg: /^-?(\d*|\d+(\.\d*)?)$/,
              component: 'reg-input'
            },
            {
              label: 'Email',
              prop: 'email',
              type: 'text',
              reg: /^([A-Za-z0-9_\-.])+@([A-Za-z0-9_\-.])+\.([A-Za-z]{2,4})$/,
              component: 'reg-input'
            },
            {
              label: '手机号',
              prop: 'phone',
              type: 'text',
              reg: /^1([3456789]\d{0,9})?$/,
              len: 11,
              component: 'reg-input'
            },
            {
              label: '身份证号',
              prop: 'idCard',
              type: 'text',
              reg: /^[1-9]\d{5}(18|19|([23]\d))\d{2}((0[1-9])|(10|11|12))(([0-2][1-9])|10|20|30|31)\d{3}[0-9Xx]$/,
              component: 'reg-input'
            },
            {
              label: '级联选择器',
              prop: 'cascader',
              type: 'cascader',
              component: 'el-cascader',
              options: options,
              style: { width: '100%' }
            },
            { label: '不可编辑', prop: 'info', type: 'info', component: 'span' }
      ]
    }
  },
  mounted() {
    setTimeout(() => {
      const length = this.formItems2.length;
      const item = this.formItems2[length - 2];
      item.options.forEach(element => {
        if (element.label === '指南') {
          element.label = '指南2'
        }
      });
    }, 1000)
  },
  methods: {
    submitForm() {
      debugger
      this.$refs[this.ref].validate(valid => {
        if (valid) {
          alert('submit!')
        } else {
          console.log('error submit!!')
          return false
        }
      })
    },
    resetForm() {
      this.$refs[this.ref].resetFields()
    }
  }
}
</script>

<!-- Add "scoped" attribute to limit CSS to this component only -->
<style scoped>
h3 {
  margin: 40px 0 0;
}
ul {
  list-style-type: none;
  padding: 0;
}
li {
  display: inline-block;
  margin: 0 10px;
}
a {
  color: #42b983;
}
</style>
